package com.fzh.Zhanye.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.fzh.Zhanye.model.Users;
import com.fzh.Zhanye.util.Constants;


public class UsersDAO {

	public Users findByUsernameAndPwd(String username, String pwd) throws SQLException {
		Connection conn=null;
		PreparedStatement pstm=null;
		ResultSet rs=null;
		Users user=null;
		try {
			conn=DBConnection.getConnection();
			String sql=Constants.SQL_USERSNAME_PWD;
			pstm=conn.prepareStatement(sql);
			pstm.setString(1, username);
			pstm.setString(2, pwd);
			rs=pstm.executeQuery();
			while(rs.next()){
				user=new Users(rs.getString("CREATOR"), rs.getDate("CREATE_TIME"),
						rs.getString("OPDATOR"), rs.getDate("OPDTE_TIME"),
						 rs.getString("USER_ID"),
						rs.getString("USERNAME"), 
						rs.getString("TRUENAME"), rs.getString("PWD"),
						rs.getString("REMARK"));
		
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			if(rs!=null){
				rs.close();
			}
			if(pstm!=null){
				pstm.close();
			}
			if(conn!=null){
				conn.close();
			}
		}
		return user;
	}

}
